import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:my_flu01/common/MyButton.dart';
import '../common/DataBean.dart';
import '../models/list_result.dart';
import '../models/list_result2.dart';
import '../models/product2.dart';
import '../models/product_model.dart';
import '../utils/api.dart';

/**
 * @author[Administrator]
 * @version[创立日期，2023/9/7 8:58]
 * @function[功用简介 ]
 * https://blog.csdn.net/a526001650a/article/details/127391917 布局
 **/
class CardViewBuilderPage extends StatefulWidget {

  final String id;
  const CardViewBuilderPage({Key? key,required this.id}) : super(key: key);

  @override
  _CardViewBuilderPage createState() => _CardViewBuilderPage();
}

class _CardViewBuilderPage extends State<CardViewBuilderPage> {
  //late ListResult<DataBean> jsonNews=getList();

  @override
  Widget build(BuildContext context) {
    //print('当前ID 是 $id');

    return Scaffold(
        appBar: AppBar(
          title: Text("card+listView"),
        ),
        body: ListView(
          children: <Widget>[
            Card(
              elevation: 1.0,
              margin: EdgeInsets.all(2),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Image.network(
                      "https://www.itying.com/images/flutter/1.png",
                      fit: BoxFit.cover,
                    ),
                    margin: EdgeInsets.all(2),
                  ),
                  ListTile(
                    leading: CircleAvatar(
                      backgroundImage: NetworkImage(
                          "https://www.itying.com/images/flutter/2.png"),
                    ),
                    title: Text("Candy Shop"),
                    subtitle: Text(
                      "Flutter is Goole's moblie UI framework for crafting higt ",
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                    ),
                  )
                ],
              ),
            ),
            Card(
              elevation: 10.0,
              margin: EdgeInsets.all(10),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Image.network(
                      "https://www.itying.com/images/flutter/5.png",
                      fit: BoxFit.cover,
                    ),
                    margin: EdgeInsets.all(10),
                  ),
                  ListTile(
                    leading: CircleAvatar(
                      backgroundImage: NetworkImage(
                          "https://www.itying.com/images/flutter/4.png"),
                    ),
                    title: Text("Candy Shop"),
                    subtitle: Text(
                      "Flutter is Goole's moblie UI framework for crafting higt ",
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                    ),
                  )
                ],
              ),
            ),
            Card(
              elevation: 20.0,
              margin: EdgeInsets.all(10),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Image.network(
                      "https://www.itying.com/images/flutter/7.png",
                      fit: BoxFit.cover,
                    ),
                    margin: EdgeInsets.all(10),
                  ),
                  ListTile(
                    leading: CircleAvatar(
                      backgroundImage: NetworkImage(
                          "https://www.itying.com/images/flutter/1.png"),
                    ),
                    title: Text("Candy Shop"),
                    subtitle: Text(
                      "Flutter is Goole's moblie UI framework for crafting higt ",
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                    ),
                  )
                ],
              ),
            ),
          ],
        )
        // This trailing comma makes auto-formatting nicer for build methods.
        );
  }

//使用ListView.builder实现：
  Widget _getListData(context, index) {
    return ListTile(
      leading: Image.network(listData[index]["imageUrl"]), // 显示在title之前
      title: Text(listData[index]['title']),
      subtitle: Text(listData[index]["author"]),
      //        显示在title之后
      trailing: Icon(Icons.phone),
      //再加子集
    );
  }
}

List listData = [
  {
    "title": "Candy Shop",
    "author": "Mohamed Chahin",
    "imageUrl": "https://www.itying.com/images/flutter/1.png",
  },
  {
    "title": "Candy Shop",
    "author": "Mohamed Chahin",
    "imageUrl": "https://www.itying.com/images/flutter/2.png",
  },
  {
    "title": "Candy Shop",
    "author": "Mohamed Chahin",
    "imageUrl": "https://www.itying.com/images/flutter/3.png",
  },
  {
    "title": "Candy Shop",
    "author": "Mohamed Chahin",
    "imageUrl": "https://www.itying.com/images/flutter/4.png",
  },
  {
    "title": "Candy Shop",
    "author": "Mohamed Chahin",
    "imageUrl": "https://www.itying.com/images/flutter/5.png",
  }
];
